package test23;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
/**
 * Created by tianxiadiyishuai on 2017/11/1.
 */
public class Test {
    //从命令行输入你的生日信息，然后计算你的生日还有多少天，你的生日是星期几
    public static void main(String[] args) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你生日的年份");
        int year = scanner.nextInt();
        System.out.println("请输入你生日的月份");
        int month = scanner.nextInt();
        System.out.println("请输入你生日的天数");
        int day = scanner.nextInt();
        System.out.println("你输入的生日为：" + year + "年" + month + "月" + day + "日");
        //获取现在的时间
        Date nowtime = new Date();
        Date date = new Date(year, month, day);
        //定义现在的时间和生日
        Calendar nowtime2 = Calendar.getInstance();
        nowtime2.setTime(nowtime);
        Calendar birthdaytime = Calendar.getInstance();
        birthdaytime.setTime(date);
        birthdaytime.add(Calendar.YEAR,-1900);
        birthdaytime.add(Calendar.MONTH,-1);
        //测试  System.out.println(nowtime2.YEAR+nowtime2.DAY_OF_YEAR);
        // System.out.println(birthdaytime.getTime());
        int nowday = nowtime2.get(Calendar.DAY_OF_YEAR);
        int nowmonth = nowtime2.get(Calendar.MONTH);
        int birthday = birthdaytime.get(Calendar.DAY_OF_YEAR);
        int birthmonth = birthdaytime.get(Calendar.MONTH);
        Calendar birth = Calendar.getInstance();
        //int birthday1 = birthdaytime1.get(Calendar.DAY_OF_YEAR);
        //int birthmonth1 = birthdaytime1.get(Calendar.MONTH);
        //相差日期的算法
        int apartday = 0;
        if (birthmonth > nowmonth) {
            apartday = nowday - birthday;
        } else if (birthmonth < nowmonth) {
            apartday = 365 - (nowday - birthday);
        } else {
            if (birthday > nowday) {
                apartday = birthday - nowday;
            } else if (birthday < nowday) {
                apartday = nowday - birthday;
            } else {
                System.out.println("祝你生日快乐！！");
            }
        }
        int week = birthdaytime.get(Calendar.DAY_OF_WEEK);
        System.out.println("距离您的生日还有：" + Math.abs(apartday) + "天");
        System.out.println("你的生日是：星期" + week);
    }
}
